<!doctype html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>有奖答题平台</title>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
    <link rel="stylesheet" href="/lib/mobile/css/common.css?111"/>
    <link rel="stylesheet" href="/lib/mobile/css/index.css?0000"/>
    <link rel="stylesheet" href="/mobile/css/bui.css" />
</head>
<body>
<div class="i_top"><img src="/lib/mobile/img/top_img.jpg" /></div>
<div class="i_banner" style="background-image: url('/lib/mobile/img/banner_1.jpg')">
    <div id="slideNote" class="ib_search bui-slide">
        <!--<div  class="bui-slide bui-slide-notice"></div>-->
    </div>
    <div class="ib_word"><img src="/lib/mobile/img/ib_word.png" alt=""/></div>
    <div class="ib_rank" id="ib_rank">
    </div>
</div>
<div class="main">
    <div class="i_rank">
        <ul class="i_rank_list">
            <li><h2>我的<br/>积分</h2></li>
            <li><h3 id="mypoint"></h3><h4>积分</h4></li>
            <li><h3 id="myrank"></h3><h4>排名</h4></li>
        </ul>
        <dl class="i_rank_entry" id="rank_person"><a href="javascript:void(0)">排行榜</a></dl>
    </div>
    <div class="i_start" id="answer">
        <dl>
            <a href="javascript:void(0)">
                <img src="/lib/mobile/img/i_start_bg.png?11" alt="">
            </a>
            <i id="myanswer"></i>
        </dl>
    </div>
    <ul class="i_product">
        <li id="coupon"><a href="javascript:void(0)"><img src="/lib/mobile/img/i_product_1.png" alt=""></a></li>
        <li id="knowledge"><a href="javascript:void(0)"><img src="/lib/mobile/img/i_product_2.png" alt=""></a></li>
    </ul>
    <div class="copyright">版权所有：天时集团能源有限公司</div>
    <ul class="bottom_menu">
        <li  id="indexsy"><a href="javascript:void(0);">首页</a></li>
        <!--<li>|</li>-->

        <li  id="hdrule"><a href="javascript:void(0);">活动规则</a></li>
        <!--<li  id="point_rule"><a href="javascript:void(0);">积分规则</a></li>-->
        <!--<li>|</li>-->
        <!--<li id="prize_rule"><a href="javascript:void(0);">抽奖规则</a></li>-->
        <!--<li>|</li>-->
        <li id="center"><a href="javascript:void(0);">个人中心</a></li>
    </ul>

</div>
<!-- 依赖库 手机调试的js引用顺序如下 -->
<script src="/lib/mobile/js/zepto.js"></script>
<script src="/lib/mobile/js/plugins/fastclick.js"></script>
<script src="/lib/mobile/js/bui.js"></script>
<script src="/lib/mobile/js/common.js?1111110    "></script>
<script>
    var dtcn=0;
    bui.ready(function () {
        // 这里写业务及控件初始化
        var storage = bui.storage();
        var uidArr = storage.get("uid");
        var uid = uidArr[0];
        bui.btn({id: ".bui-page", handle: ".bui-btn"}).load();
        var pageview = {};
        var phone = getCookie("phone");
        // $("#phone").val(phone);
        // console.log(phone+"=="+uid);
        if(phone!=''){
            if(!uid) {
                var loginAjax = bui.ajax({
                    url: BASE_URL+"mobile/load",
                    // 可选参数
                    data: {
                        phone:phone,
                        flag:'check'
                    },
                    method: "POST"
                });
                loginAjax.then(function (res) {
                    if (res.code == 0) {
                        var user = res.data;
                        // console.log(user);
                        if (user) {
                            var storage = bui.storage();
                            var token = user.token;
                            storage.set("yhbm", user.xm);
                            storage.set("phone", user.phone);
                            storage.set("user", user);
                            storage.set("uid", user.id);
                            storage.set("token", token);
                            TOKEN = token;
                            bui.config.ajax = {
                                headers: {
                                    token: token
                                }
                            };
                            bui.load({url: BASE_URL + "mobile/index"});
                        }
                    } else {
                        bui.load({ url: BASE_URL+"mobile/login"});
                    }
                }, function (res) {
                    bui.alert("请求异常");
                })
            }else if(uid){
                var loginAjax = bui.ajax({
                    url: BASE_URL+"mobile/autoLogin",
                    // 可选参数
                    data: {
                        phone:phone
                    },
                    method: "POST"
                });
                loginAjax.then(function (res) {
                    // console.log(res);
                    if(res.code == 0){
                        var user = res.data;
                        // console.log(user)
                        if(user){
                            var storage = bui.storage();
                            var token = user.token;
                            storage.set("yhbm",user.xm);
                            storage.set("phone",user.phone);
                            storage.set("user",user);
                            storage.set("uid",user.id);
                            storage.set("token",token);
                            TOKEN = token;
                            bui.config.ajax = {
                                headers: {
                                    token:token
                                }
                            };
                        }
                        // bui.load({ url: BASE_URL+"mobile/index"});
                    }else{
                        bui.load({ url: BASE_URL+"mobile/login"});
                    }
                }, function (res) {
                })
            }
        }else{
            bui.load({ url: BASE_URL+"mobile/login"});
        }
        pageview.init = function () {
            //展示答题次数
            getMyPointList(uid,'');
            // 判断是否进入答题窗口
            $("#answer").on("click", function (argument) {
                getMyPointList(uid,'');
                if(dtcn<=5){
                    bui.confirm({
                        content: "每月限答题5次，点击确定进入答题窗口！",
                        title: "开始答题",
                        buttons: ["取消", "确定"],
                        callback: function (e) {
                            var text = $(e.target).text();
                            if( text == "确定") {
                                bui.load({url: BASE_URL + "mobile/answer"});
                            }else{
                                bui.alert("已取消答题！");
                            }
                        }
                    });
                }else if(dtcn>5){
                    bui.alert("本月答题"+dtcn+"次，请明天再来！");
                }

            });
            $("#coupon").on("click", function (argument) {
                bui.load({ url: BASE_URL+"mobile/coupon"});
            });
            $("#knowledge").on("click", function (argument) {
                bui.load({ url: BASE_URL+"mobile/knowledge"});
            });
            $("#rank_person").on("click", function (argument) {
                bui.load({ url: BASE_URL+"mobile/rank_person"});
            });
            $("#indexsy").on("click", function (argument) {
                bui.load({ url: BASE_URL+"mobile/index"});
            });
            $("#point_rule").on("click", function (argument) {
                bui.load({ url: BASE_URL+"mobile/point_rule"});
            });
            $("#prize_rule").on("click", function (argument) {
                bui.load({ url: BASE_URL+"mobile/prize_rule"});
            });
            $("#center").on("click", function (argument) {
                bui.load({ url: BASE_URL+"mobile/center"});
            });

            // 后退的时候,清除掉自动播放
            // function beforeBack(e) {
            //     if (e.target.pid == "pages/ui_controls/bui.slide_note") {
            //         // 禁止自动播放
            //         uiSlide.stop();
            //         // 去掉实例缓存
            //         uiSlide = null;
            //     }
            // }
            // // 示例后退以后清除掉实例, 每次进来都会增加
            // if (router.handle["beforeback"]) {
            //     var hasHandle = false;
            //     router.handle["beforeback"].forEach(function(item) {
            //         // 如果 function 的名称相同,则不用再增加
            //         if (item.name === "beforeBack") {
            //             hasHandle = true;
            //             return hasHandle;
            //         }
            //     })
            //
            //     // 第一次增加
            //     !hasHandle && router.on("beforeback", beforeBack)
            // } else {
            //     // 第一次增加
            //     router.on("beforeback", beforeBack)
            // }


            // var uid=storage.get("uid");
            //我的积分
            // console.log(uid[0]);
            getMyponit(uid);
            getMyponit1();
            getIndexPic();
            getDayAwardList();
            // getPersonDayRankList(uid[0]);
        }
        pageview.init();
    })
    function getMyPointList(uid,rq) {
        // console.log(uid+rq)
        //执行登录操作
        var loginAjax = bui.ajax({
            url: BASE_URL+"mobile/getMyPointList",
            // 可选参数
            data: {
                uid:uid,
                rq:rq
            },
            method: "POST"
        });
        loginAjax.then(function(res) {

            if(res.code == 0){
                var user = res.data;
                dtcn=user.dtcn;
                // console.log(dtcn+"==");
                if(!dtcn){
                    dtcn="0";
                }
                var rpoint=user.rpoint;
                if(!rpoint){
                    rpoint="0";
                }
                $("#myanswer").html("本月已答"+dtcn+"次 积"+rpoint+"分");
            }else{
                bui.alert(res.msg);
            }
        },function(res) {
            bui.alert("请求异常");
        })
    }
    function getIndexPic() {
        //执行登录操作
        var loginAjax = bui.ajax({
            url: BASE_URL+"mobile/getIndexPic",
            // 可选参数
            data: {
            },
            method: "POST"
        });
        loginAjax.then(function(res) {
            if(res.code == 0){
                var pic = res.data;
                if(pic){
                    $(".i_top").html("<img src=\""+pic+"\" alt=\"\">");
                }else{
                    // $(".i_top").css({"background-image":"url('/lib/mobile/img/banner_1.jpg')"});
                    // background-image: url('/lib/mobile/img/banner_1.jpg')
                    $(".i_top").html("<img src=\"/lib/mobile/img/top_img.jpg?11\" alt=\"\">");
                }

            }else{
                bui.alert(res.msg);
            }
        },function(res) {
            bui.alert("请求异常");
        })
    }
    function getMyponit(uid) {
        //执行登录操作
        var loginAjax = bui.ajax({
            url: BASE_URL+"mobile/myPersonPoint",
            // 可选参数
            data: {
                page:1,
                pageSize:1,
                uid:uid,
                ny:'',
                flag:'month'
            },
            method: "POST"
        });
        loginAjax.then(function(res) {
            if(res.code == 0){
                var user = res.data;
                if(user.length>0){
                    $("#mypoint").html(user[0].point);
                    $("#myrank").html(user[0].rankpx);
                }else{
                    $("#mypoint").html("");
                    $("#myrank").html("");
                }
            }else{
                bui.alert(res.msg);
            }
        },function(res) {
            bui.alert("请求异常");
        })
    }
    function getMyponit1() {
        //执行登录操作
        var loginAjax = bui.ajax({
            url: BASE_URL+"mobile/myPersonPoint",
            // 可选参数
            data: {
                page:1,
                pageSize:3,
                ny:'',
                uid:'',
                flag:'month'
            },
            method: "POST"
        });
        loginAjax.then(function(res) {
            if(res.code == 0){
                var user = res.data;
                if(user.length>=3){
                    $("#ib_rank").html("<div class=\"rank_panel rank_two\">\n" +
                        "            <dl class=\"rank_head\"><img src=\"/lib/mobile/img/uhead.png?121111\" alt=\"\"></dl>\n" +
                        "            <dl class=\"rank_content\">\n" +
                        "                <dt>2</dt>\n" +
                        "                <dd>\n" +
                        "                    <p class=\"rank_text_name\">"+user[1].usrname+"</p>\n" +
                        "                    <p class=\"rank_text_statistic\">\n" +
                        "                        <img src=\"/lib/mobile/img/star.png\" alt=\"\">\n" +
                        "                        <span>"+user[1].point+"</span>\n" +
                        "                    </p>\n" +
                        "                </dd>\n" +
                        "            </dl>\n" +
                        "        </div>\n" +
                        "        <div class=\"rank_panel rank_three\">\n" +
                        "            <dl class=\"rank_head\"><img src=\"/lib/mobile/img/uhead.png?121111\" alt=\"\"></dl>\n" +
                        "            <dl class=\"rank_content\">\n" +
                        "                <dt>3</dt>\n" +
                        "                <dd>\n" +
                        "                    <p class=\"rank_text_name\">"+user[2].usrname+"</p>\n" +
                        "                    <p class=\"rank_text_statistic\">\n" +
                        "                        <img src=\"/lib/mobile/img/star.png\" alt=\"\">\n" +
                        "                        <span>"+user[2].point+"</span>\n" +
                        "                    </p>\n" +
                        "                </dd>\n" +
                        "            </dl>\n" +
                        "        </div>\n" +
                        "        <div class=\"rank_panel rank_first\">\n" +
                        "            <dl class=\"rank_head\"><img src=\"/lib/mobile/img/uhead.png?11211\" alt=\"\"></dl>\n" +
                        "            <dl class=\"rank_content\">\n" +
                        "                <dt>1</dt>\n" +
                        "                <dd>\n" +
                        "                    <p class=\"rank_text_name\">"+user[0].usrname+"</p>\n" +
                        "                    <p class=\"rank_text_statistic\">\n" +
                        "                        <img src=\"/lib/mobile/img/star.png\" alt=\"\">\n" +
                        "                        <span>"+user[0].point+"</span>\n" +
                        "                    </p>\n" +
                        "                </dd>\n" +
                        "            </dl>\n" +
                        "        </div>");
                }else if(user.length>0){
                    $("#ib_rank").html( "        <div class=\"rank_panel rank_first\">\n" +
                        "            <dl class=\"rank_head\"><img src=\"/lib/mobile/img/uhead.png?112111\" alt=\"\"></dl>\n" +
                        "            <dl class=\"rank_content\">\n" +
                        "                <dt>1</dt>\n" +
                        "                <dd>\n" +
                        "                    <p class=\"rank_text_name\">"+user[0].usrname+"</p>\n" +
                        "                    <p class=\"rank_text_statistic\">\n" +
                        "                        <img src=\"/lib/mobile/img/star.png\" alt=\"\">\n" +
                        "                        <span>"+user[0].point+"</span>\n" +
                        "                    </p>\n" +
                        "                </dd>\n" +
                        "            </dl>\n" +
                        "        </div>");
                }
            }else{
                bui.alert(res.msg);
            }
        },function(res) {
            bui.alert("请求异常");
        })
    }
    function getDayAwardList() {
        // 通知, 自定义模板
        var uiSlide = bui.slide({
            id: "#slideNote",
            height: 70,
            autoplay: true,
            loop: true,
            swipe: false,
            data: [],
            template: function(data) {
                // 自定义模板时,需要自己渲染完整结构
                var html = "";
                // console.log(data)
                html += "<div class='bui-slide-main'><ul>";
                for(var i=0;i<data.length;i++){
                        html+="<input type=\"text\" value=\""+data[i].usrname+"被"+data[i].award+"个智慧币砸中 \"/>";
                }
                html += "</ul></div>";
                return html;
            },
            direction: "x",
            // 示例跳转前去掉自动播放, 如果不需要自动播放, 模板直接给 href 属性就行, 不用 data-href
            // callback: function(e) {
            //     var $item = $(e.target).parents("li"),
            //         href = $item.attr("data-href"),
            //         that = this;
            //     bui.load({
            //         url: href,
            //         beforeLoad: function() {
            //             // 跳转前去掉自动播放.
            //             that.stop();
            //         }
            //     })
            // }
        })
        //执行登录操作
        var loginAjax = bui.ajax({
            url: BASE_URL+"mobile/getDayAwardList",
            // 可选参数
            data: {
                page:1,
                pageSize:5
            },
            method: "POST"
        });
        loginAjax.then(function(res) {
            // console.log(res.data)
            uiSlide.option("data",res.data);
        },function(res) {
            bui.alert("请求异常");
        })
    }
</script>
</body>
</html>
